//初始化一些必须的操作
import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';

import 'constans/all_info.dart';
import 'constans/constants.dart';
import 'constans/route_constants.dart';
import 'utils/sp_utils.dart';

import 'package:rammus/rammus.dart' as rammus;

Future<void> initApp(BuildContext context) async {
  //初始化本地缓存
  SpUtil.init();
  String token = await SpUtil.getStringItem(Constants.accessToken);
  AllInfo.instance.setToken(token == null ? "" : token);
  String userStr = await SpUtil.getStringItem(Constants.SP_USER);
  AllInfo.instance.setUserinfo(userStr == null ? "" : userStr);
  rammus.initCloudChannelResult.listen((data) {
    print("----------->init successful ${data.isSuccessful} ${data.errorCode} ${data.errorMessage}");
  });
  String deviceId="";
  try {
    deviceId = await rammus.deviceId;
  } on PlatformException {
    deviceId = 'Failed to get device id.';
  }
  // print("===============ios 推送初始化================"+deviceId);
  rammus.configureNotificationPresentationOption();
  var channels = List<rammus.NotificationChannel>();
  channels.add(rammus.NotificationChannel(
      "android_channel1",
      "校视安",
      "校视安推送",
      importance: rammus.AndroidNotificationImportance.MAX
  ));
  rammus.setupNotificationManager(channels);


}
